package com.fingard.dsp.bank.directbank.citic01;

import org.apache.commons.lang.StringUtils;

import com.fingard.dsp.bank.directbank.bankInterface.IElecBillQuery;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.*;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.*;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

public class CITIC01ElecBill extends CITIC01Base implements IElecBillQuery
{
    public RetAtsB001OperBillQry D_OperBill_Query_Req(ReqB001OperBillQry query) throws Exception {
        return D_OperBill_Query(query);
    }

    public boolean queryBillDetail(double moneyOff, double moneyEnd, RetAtsB001OperBillQry Resp, ReqB001OperBillQry query, String reqCode) throws Exception {
        XmlTextWriter xmlWriter = new XmlTextWriter();
        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
        XElement tmpElemnt = new XElement("stream", "");
        tmpElemnt.addChild(new XElement("action", "DLBCMQJB"));
        tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
        tmpElemnt.addChild(new XElement("reqCode", reqCode));
        tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
        tmpElemnt.addChild(new XElement("dueDateDown", TransDateFromATS(query.detail.dueDateDown)));
        tmpElemnt.addChild(new XElement("dueDateUp", TransDateFromATS(query.detail.dueDateUp)));
        int billType = Integer.parseInt(query.detail.billType);
        switch (billType) {
            case 1:
                tmpElemnt.addChild(new XElement("billType", "AC01"));
                break;
            case 2:
                tmpElemnt.addChild(new XElement("billType", "AC02"));
                break;
        }
        tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
        tmpElemnt.addChild(new XElement("orgName", ""));
        tmpElemnt.addChild(new XElement("rcvName", ""));

        tmpElemnt.addChild(new XElement("billAmtDown", String.format("%.2f", moneyOff)));
        tmpElemnt.addChild(new XElement("billAmtUp", String.format("%.2f", moneyEnd)));
        tmpElemnt.addChild(new XElement("ecdsBatNo", ""));
        if (reqCode.equals("DLTSFKSQ") || reqCode.equals("DLTSFKQS") || reqCode.equals("DLTSFKCX")) {
            int overdueFlag = Integer.parseInt(query.detail.overdueFlag);
            switch (overdueFlag) {
                case 1:
                    tmpElemnt.addChild(new XElement("odueFlg", "01"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("odueFlg", "02"));
                    break;
                default:
                    throw new Exception("逾期标志错误");
            }
        }
        if (reqCode.equals("DLZSTZSQ") || reqCode.equals("DLZSTZCX")) {
            int recourseType = Integer.parseInt(query.detail.recourseType);
            switch (recourseType) {
                case 1:
                    tmpElemnt.addChild(new XElement("rcrsType", "RT00"));
                    break;
                case 2:
                    tmpElemnt.addChild(new XElement("rcrsType", "RT01"));
                    break;
                default:
                    throw new Exception("追索类型错误");
            }

        }
//        nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpXElement, getCharset());
        xmlWriter.writeXElement(tmpElemnt);
        xmlWriter.writeEndDocument();
//        WriteBankLogStep2(xmlWriter.getSbXml());
//        String[] tmpStrRet;
//        if(moneyEnd-moneyOff>3000000000000.99){
//            tmpStrRet=new String[]{"","<?xml version=\"1.0\" encoding=\"GB2312\"?><stream><status>BPCM019</status><statusText>查询范围过大,请缩小查询范围</statusText></stream>"};
//        }else{
//            tmpStrRet=new String[]{"","<?xml version=\"1.0\" encoding=\"GBK\"?>\n" +
//                    "<stream><status>AAAAAAA</status><statusText>交易成功</statusText><list name=\"userDataList\"/></stream>"};
//        }
//        WriteBankLogStep3(tmpStrRet[1]);
        String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String returnCode = tmpBkReader.getFirstText("/stream/status");
                String returnInfo = tmpBkReader.getFirstText("/stream/statusText");
                if ("AAAAAAA".equals(returnCode)) {
                    //Resp.WriteBefore();
                    int DetailCount = tmpBkReader.countElement("/stream/list/row");
                    if (DetailCount > 0) {
                        while (tmpBkReader.read("/stream/list/row")) {
                            RetAtsB001OperBillQryDetail RespDetail = new RetAtsB001OperBillQryDetail();
                            RespDetail.billNo = tmpBkReader.readedXElement.getSingleText("billNo");
                            if (tmpBkReader.readedXElement.getSingleText("BILLTYP").equals("AC01")) {
                                RespDetail.billType = "1";
                            } else {
                                RespDetail.billType = "2";
                            }
                            RespDetail.issDate = TransDate(tmpBkReader.readedXElement.getSingleText("ISSDATE"));
                            RespDetail.dueDate = TransDate(tmpBkReader.readedXElement.getSingleText("DUEDATE"));
                            RespDetail.billAmt = tmpBkReader.readedXElement.getSingleText("PAYAMT");
                            if (tmpBkReader.readedXElement.getSingleText("ENDORMK").equals("EM00")) {
                                RespDetail.transFlag = "1";
                            } else if(tmpBkReader.readedXElement.getSingleText("ENDORMK").equals("EM01")) {
                                RespDetail.transFlag = "0";
                            } else if(tmpBkReader.readedXElement.getSingleText("DFENDMK").equals("EM00")) {
                                RespDetail.transFlag = "1";
                            } else if(tmpBkReader.readedXElement.getSingleText("DFENDMK").equals("EM01")) {
                                RespDetail.transFlag = "0";
                            }
                            if (tmpBkReader.readedXElement.getSingleText("UNCNPAY").equals("CC00")) {
                                RespDetail.mustPay = "1";
                            } else if(tmpBkReader.readedXElement.getSingleText("UNCNPAY").equals("CC01")) {
                                RespDetail.mustPay = "0";
                            }
                            RespDetail.drawName = tmpBkReader.readedXElement.getSingleText("DRWRNAM");
                            RespDetail.drawCode = tmpBkReader.readedXElement.getSingleText("DRWRCOD");
                            RespDetail.drawAct = tmpBkReader.readedXElement.getSingleText("DRWRACC");
                            RespDetail.drawBnkCode = tmpBkReader.readedXElement.getSingleText("DRWRBNM");

                            RespDetail.accpName = tmpBkReader.readedXElement.getSingleText("ACCPNAM");
                            RespDetail.accpCode = tmpBkReader.readedXElement.getSingleText("ACCPCOD");
                            RespDetail.accpAct = tmpBkReader.readedXElement.getSingleText("ACCPACC");
                            RespDetail.accpBnkCode = tmpBkReader.readedXElement.getSingleText("ACCPBNM");

                            RespDetail.payeeName = tmpBkReader.readedXElement.getSingleText("PYEENAM");
                            RespDetail.payeeCode = tmpBkReader.readedXElement.getSingleText("PYEECOD");
                            RespDetail.payeeAct = tmpBkReader.readedXElement.getSingleText("PYEEACC");
                            RespDetail.payeeBnkCode = tmpBkReader.readedXElement.getSingleText("PYEEBNM");

                            RespDetail.busiNo = tmpBkReader.readedXElement.getSingleText("BUSSQNO");
                            RespDetail.busiType = query.detail.busiType;

                            String tmpAPPDATE = tmpBkReader.readedXElement.getSingleText("APPDATE");
                            if (!"".equals(tmpAPPDATE) && !"00000000".equals(tmpAPPDATE)) {
                                RespDetail.applyDate = TransDate(tmpAPPDATE);
                            }
                            RespDetail.applyName = tmpBkReader.readedXElement.getSingleText("APPNAME");
                            RespDetail.applyCode = tmpBkReader.readedXElement.getSingleText("APPCODE");
                            RespDetail.applyAct = tmpBkReader.readedXElement.getSingleText("APPACCT");
                            RespDetail.applyBnkCode = tmpBkReader.readedXElement.getSingleText("APPBNM");

                            RespDetail.receName = tmpBkReader.readedXElement.getSingleText("RCVNAME");
                            RespDetail.receCode = tmpBkReader.readedXElement.getSingleText("RCVCODE");
                            RespDetail.receAct = tmpBkReader.readedXElement.getSingleText("RCVACCT");
                            RespDetail.receBnkCode = tmpBkReader.readedXElement.getSingleText("RCVBNM");

                            RespDetail.memo = tmpBkReader.readedXElement.getSingleText("MEMO");
                            RespDetail.contractNo = tmpBkReader.readedXElement.getSingleText("CONTRACTNO");
                            RespDetail.invoiceNo = tmpBkReader.readedXElement.getSingleText("INVOICENO");

                            String payType = tmpBkReader.readedXElement.getSingleText("STLMTHD");
                            if (StringHelper.hasAnyChar(payType)) {
                                if("SM00".equals(payType)){
                                RespDetail.payType = "1";
                                 } else if("SM01".equals(payType)) {
                                RespDetail.payType = "2";

                            }
                            }

                            RespDetail.overDueFlag =query.detail.overdueFlag;
                            if("DLTSFKQS".equals(reqCode)) {
                            RespDetail.overDueRea = tmpBkReader.readedXElement.getSingleText("ODUERSN");
                            }
                            RespDetail.recourseType =query.detail.recourseType;
                            if("DLTYQCSQ".equals(reqCode)){
                                String recourseType =tmpBkReader.readedXElement.getSingleText("RCRSTYP");
                                if ("RT00".equals(recourseType)) {
                                RespDetail.recourseType = "1";
                            } else {
                                RespDetail.recourseType = "2";
                            }

                            RespDetail.recourseAmt = tmpBkReader.readedXElement.getSingleText("RCRSAMT");
                            }

                            if (tmpBkReader.readedXElement.getSingleText("RCRSBCD").equals("RC00")) {
                                RespDetail.recourseCode = "1";
                            } else {
                                RespDetail.recourseCode = "2";
                            }

                            RespDetail.billStatus = tmpBkReader.readedXElement.getSingleText("BILSTAT");


                            Resp.writeDetail(RespDetail);
                        }

                    } //
                    return true;
                } else if ("BPCM019".equals(returnCode)) {
                    if ("查询范围过大,请缩小查询范围".equals(returnInfo)) {
                        return false;
                    } else {
                        throw new Exception(returnInfo);
                    }
                } else {
                    throw new Exception(returnInfo);
                }
            } else {
                throw new Exception(tmpSbMsg.toString());
                //Resp.Head();
            }
        } else {
            throw new Exception(tmpStrRet[1]);
        }
    }

    private void queryAllBill(double moneyOff, double moneyEnd, RetAtsB001OperBillQry resp, ReqB001OperBillQry query, String reqCode) throws Exception {
        //返回为false时，代表查询范围过大，这是对查询金额进行二分再次查询
        boolean flag = queryBillDetail(moneyOff, moneyEnd, resp, query, reqCode);
        if (!flag) {
            BigDecimal moneyDownStart = new BigDecimal(moneyOff);
            BigDecimal moneyUpEnd = new BigDecimal(moneyEnd);
            String middle = moneyUpEnd.add(moneyDownStart).divide(new BigDecimal(2)).setScale(2, BigDecimal.ROUND_DOWN).toString();
            double moneyDownEnd = Double.valueOf(middle);
            //由于银行金额保留2位小数
            double moneyUpStart = moneyDownEnd + 0.01;
            if (moneyOff < moneyDownEnd) {
                queryAllBill(moneyOff, moneyDownEnd, resp, query, reqCode);
            }
            if (moneyUpStart < moneyEnd) {
                queryAllBill(moneyUpStart, moneyEnd, resp, query, reqCode);
            }
        }
    }

    public RetAtsB002BillTransQry D_B002_BillTrans_Query(ReqB002BillTransQry query) throws Exception {
        return D_B002_BillTrans(query);
    }

    public RetAtsB004BillFrontQry D_B004_BillFront_Query(ReqB004BillFrontQry query) throws Exception {
        return D_B004_BillFront(query);
    }

    private String getBillCurStatue(String billNo,String actNum){
        String billStatus = "";
        try {
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            xmlWriter.writeStartElement("stream");
//            <action>DLBCMBDQ</action>
            xmlWriter.writeElementString("action","DLBCMBDQ");
//            <userName></userName><!--登录名 varchar(30)-->
            xmlWriter.writeElementString("userName",bankFront.loginName);
//            <infoType></infoType><!--票据信息类型 char(4) 电子票据序列号为空时非空，类型见附录4.1.9-->
            xmlWriter.writeElementString("infoType","");
//            <accountNo></accountNo><!--签约账号 char(19)-->
            xmlWriter.writeElementString("accountNo",actNum);
//            <billNo></billNo><!--电子票据序列号 char(30) 可空，若电子票据序列号不为空，则按电子票据序列号查询，若电子票据序列号为空，则票据信息类型不可空-->
            xmlWriter.writeElementString("billNo",billNo);
//            <startDate></startDate><!--起始日期 char(8) 格式YYYYMMDD 可空-->
            xmlWriter.writeElementString("startDate","");
//            <endDate></endDate><!--截止日期 char(8) 格式YYYYMMDD 可空-->
            xmlWriter.writeElementString("endDate","");
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                     return tmpBkReader.getFirstText("/stream/list/row/BILSTAT");
                }else {
                    throw new Exception(tmpSbMsg.toString());
                }
            }else{
               throw new Exception(tmpStrRet[1]);
            }
        }catch (Exception ex){
            ex.getStackTrace();
        }
        return billStatus;
    }

    public RetAtsB005BillBackQry D_B005_BillBack_Query(ReqB005BillBackQry query) throws Exception {
        return D_B005_BillBack(query);
    }

    public RetAtsB006BillStateQry D_B006_BillState_Qeury(ReqB006BillStateQry query) throws Exception {
        return D_B006_BillState(query);
    }

    public RetAtsB007BillKzsrQry D_B007_BillKzsr_Query(ReqB007BillKzsrQry query) throws Exception {
        return D_B007_BillKzsr(query);
    }

    protected String TransDate(String date) {
//        String year = date.substring(0, 4);
//        String month = date.substring(4, 6);
//        String day = date.substring(6, 8);

//        return month + "/" + day + "/" + year;
        return DateHelper.convertD8toD10(date);
    }

    @Override
    public RetAtsB008HistoricalBillQry D_B008_HistoricalBillQuery(ReqB008HistoricalBillQry query) throws Exception {
        RetAtsB008HistoricalBillQry result = new RetAtsB008HistoricalBillQry(reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        String reqCode = "";
        if (query.readRecord()) {
            if (StringHelper.isNullOrEmpty(query.detail.billNo)) {
                int queryType = Integer.parseInt(query.detail.queryType);
                int busiType = Integer.parseInt(query.detail.busiType);
                //<editor-fold desc="处理reqCode">
                switch (queryType) {
                    case 1://发起方
                        switch (busiType) {
                            case 1://提示收票
                                reqCode = "0103";
                                break;
                            case 2: //背书转让
                                reqCode = "0105";
                                break;
                            case 3://贴现
                                reqCode = "0106";
                                break;
                            case 10://质押
                                reqCode = "0115";
                                break;
                            default:
                                result.respCode = "-1";
                                result.respInfo = "不支持该业务类型";
                                result.writeBefore();
                                result.writeAfter();
                                return result;
                        }
                        break;
                    case 2://接收方
                        switch (busiType) {
                            case 1://提示收票
                                reqCode = "0203";
                                break;
                            case 2: //背书转让
                                reqCode = "0205";
                                break;
                            case 3: //贴现
                                reqCode = "0206";
                                break;
                            case 10: //质押
                                reqCode = "0215";
                                break;
                            default:
                                result.respCode = "-1";
                                result.respInfo = "不支持该业务类型";
                                result.writeBefore();
                                result.writeAfter();
                                return result;
                        }
                        break;
                    default:
                        result.respCode = "-1";
                        result.respInfo = "不支持该业务类型";
                        result.writeBefore();
                        result.writeAfter();
                        return result;
                }
            }
            //</editor-fold>

            //<editor-fold desc="拼接发送报文">
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBCMBDQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("infoType", reqCode));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("startDate", query.detail.dueDateDown));
            tmpElemnt.addChild(new XElement("endDate", query.detail.dueDateUp));
            //</editor-fold>

            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    result.respInfo = tmpBkReader.getFirstText("/stream/statusText");
                    if ("AAAAAAA".equals(tmpBkReader.getFirstText("/stream/status"))) {
                        result.respCode = "0";
                        if ("0".equals(tmpBkReader.getFirstText("/stream/totalNum"))) {
                            result.respInfo = "记录为空";
                            result.writeBefore();
                        } else {
                            int DetailCount = tmpBkReader.countElement("/stream/list/row");
                            if (DetailCount > 0) {
                                result.writeBefore();
                                while (tmpBkReader.read("/stream/list/row")) {
                                    RetAtsB008HistoricalBillQryDetail respDetail = new RetAtsB008HistoricalBillQryDetail();
                                    respDetail.billNo = tmpBkReader.readedXElement.getSingleText("BILLNUM");
                                    if (tmpBkReader.readedXElement.getSingleText("BILLTYP").equals("AC01")) {
                                        respDetail.billType = "1";
                                    } else {
                                        respDetail.billType = "2";
                                    }
                                    respDetail.issDate = TransDate(tmpBkReader.readedXElement.getSingleText("ISSDATE"));
                                    respDetail.dueDate = TransDate(tmpBkReader.readedXElement.getSingleText("DUEDATE"));
                                    respDetail.billAmt = tmpBkReader.readedXElement.getSingleText("PAYAMT");
                                    respDetail.drawName = tmpBkReader.readedXElement.getSingleText("DRWRNAM");
                                    respDetail.drawCode = tmpBkReader.readedXElement.getSingleText("DRWRCOD");
                                    respDetail.drawAct = tmpBkReader.readedXElement.getSingleText("DRWRACC");
                                    respDetail.drawBnkCode = tmpBkReader.readedXElement.getSingleText("DRWRBNM");
                                    respDetail.creditLv = tmpBkReader.readedXElement.getSingleText("DRCDRAT");
                                    respDetail.gradeAgent = tmpBkReader.readedXElement.getSingleText("DRRAGCY");
                                    respDetail.drawBnkCode = tmpBkReader.readedXElement.getSingleText("DRWRBNM");
                                    respDetail.drawBnkCode = tmpBkReader.readedXElement.getSingleText("DRWRBNM");
                                    if (StringUtils.isNotBlank(tmpBkReader.readedXElement.getSingleText("RDUEDAT"))) {
                                        respDetail.gradeDueDate = TransDate(tmpBkReader.readedXElement.getSingleText("RDUEDAT"));
                                    }
                                    respDetail.accpName = tmpBkReader.readedXElement.getSingleText("ACCPNAM");
                                    respDetail.accpCode = tmpBkReader.readedXElement.getSingleText("ACCPCOD");
                                    respDetail.accpAct = tmpBkReader.readedXElement.getSingleText("ACCPACC");
                                    respDetail.accpBnkCode = tmpBkReader.readedXElement.getSingleText("ACCPBNM");
                                    respDetail.payeeName = tmpBkReader.readedXElement.getSingleText("PYEENAM");
                                    respDetail.payeeCode = tmpBkReader.readedXElement.getSingleText("PYEECOD");
                                    respDetail.payeeAct = tmpBkReader.readedXElement.getSingleText("PYEEACC");
                                    respDetail.payeeBnkCode = tmpBkReader.readedXElement.getSingleText("PYEEBNM");
                                    if (StringUtils.isNotBlank(tmpBkReader.readedXElement.getSingleText("BILSTAT"))) {
                                        respDetail.billStatus = tmpBkReader.readedXElement.getSingleText("BILSTAT");
                                    }
                                    respDetail.busiType = query.detail.busiType;
                                    respDetail.queryType = query.detail.queryType;
                                    result.writeDetail(respDetail);
                                }
                            } else {
                                result.respCode = "-1";
                                result.respInfo = "记录为空";
                                result.writeBefore();
                            }
                        }
                    } else {
                        result.respCode = "-1";
                        result.writeBefore();
                    }
                } else {
                    result.respCode = "-1";
                    result.respInfo = tmpSbMsg.toString();
                    result.writeBefore();
                }
            } else {
                result.respCode = "-1";
                result.respInfo = tmpStrRet[1];
                result.writeBefore();
            }
        }

        result.writeAfter();
        return result;
    }

    @Override
    public RetAtsB009DrawBillQry D_B009_DrawBillQuery(ReqB009DrawBillQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB010ProtocolStateQry D_B010_ProtocolStateQuery(ReqB010ProtocolStateQry query) throws Exception {
        return null;
    }

    @Override
    public RetAtsB011TransFlagQry D_B011_TransFlagQuery(ReqB011TransFlagQry query) throws Exception {
        return null;
    }

    public String TransDateFromATS(String ATS) throws Exception {
        if (StringHelper.isNullOrEmpty(ATS)) {
            return "";
        }
        String[] date = ATS.split("/");
        String year = date[0];
        String month = date[1];
        if (month.length() == 1) {
            month = "0" + month;
        }
        String day = date[2].substring(0, 1);
        if (day.trim().length() == 1) {
            day = "0" + day.trim();
        }
        return year + month + day;
    }

    public RetAtsB001OperBillQry D_OperBill_Query(ReqB001OperBillQry query) throws Exception {
        RetAtsB001OperBillQry Resp = new RetAtsB001OperBillQry(query.reqHeader);
        Resp.respCode = "0";
        //Resp.writeStart();
        query.readRecord();
        String reqCode = "";
        //D_OperBill_Query_Resp Resp = new D_OperBill_Query_Resp();
        int queryType = Integer.parseInt(query.detail.queryType);
        int busiType = Integer.parseInt(query.detail.busiType);
        switch (queryType) {
            case 1:
                switch (busiType) {
                    case 1:
//                            reqCode = "";
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                    case 2:
                        reqCode = "DLTSCDSQ";
                        break;
                    case 3:
                        reqCode = "DLTSSPSQ";
                        break;
                    case 4:
                        reqCode = "DLBSZRSQ";
                        break;
                    case 5:
                        reqCode = "DLZHYASQ";
                        break;
                    case 6:
                        reqCode = "DLZYJCSQ";
                        break;
                    case 7:
                        reqCode = "DLBOZHSQ";
                        break;
                    case 8:
                        reqCode = "DLBOZHSQ";
                        break;
                    case 9:
                        reqCode = "DLBOZHSQ";
                        break;
                    case 10:
                        reqCode = "DLTIEXSQ";
                        break;
                    case 11:
                        reqCode = "DLTXSHSQ";
                        break;
                    case 12:
                        reqCode = "DLTSFKSQ";
                        break;
                    case 13:
                        reqCode = "DLZSTZSQ";
                        break;
                    case 14:
                        reqCode = "DLTYQCSQ";
                        break;
                    default:
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                }
                break;
            case 2: {
                switch (busiType) {
                    case 1:
//                            reqCode = "";
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                    case 2:
                        reqCode = "DLTSCDQS";
                        break;
                    case 3:
                        reqCode = "DLTSSPQS";
                        break;
                    case 4:
                        reqCode = "DLBSZRQS";
                        break;
                    case 5:
                        reqCode = "DLZHYAQS";
                        break;
                    case 6:
                        reqCode = "DLZYJCQS";
                        break;
                    case 7:
                        reqCode = "DLBOZHQS";
                        break;
                    case 8:
                        reqCode = "DLBOZHQS";
                        break;
                    case 9:
                        reqCode = "DLBOZHQS";
                        break;
                    case 10:
                        reqCode = "DLTIEXQS";
                        break;
                    case 11:
                        reqCode = "DLTXSHQS";
                        break;
                    case 12:
                        reqCode = "DLTSFKQS";
                        query.detail.overdueFlag ="1";
                        break;
                    case 13:
//                            reqCode = "";
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                    case 14:
                        reqCode = "DLTYQCQS";
                        break;
                    default:
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                }
            }
            break;
            case 3: {
                switch (busiType) {
                    case 1:
                        reqCode = "DLWYTHSQ";
                        break;
                    case 2:
                        reqCode = "DLTSCDCX";
                        break;
                    case 3:
                        reqCode = "DLTSSPCX";
                        break;
                    case 4:
                        reqCode = "DLBSZRCX";
                        break;
                    case 5:
                        reqCode = "DLZHYACX";
                        break;
                    case 6:
                        reqCode = "DLZYJCCX";
                        break;
                    case 7:
                        reqCode = "DLBOZHCX";
                        break;
                    case 8:
                        reqCode = "DLBOZHCX";
                        break;
                    case 9:
                        reqCode = "DLBOZHCX";
                        break;
                    case 10:
                        reqCode = "DLTIEXCX";
                        break;
                    case 11:
                        reqCode = "DLTXSHCX";
                        break;
                    case 12:
                        reqCode = "DLTSFKCX";
                        break;
                    case 13:
                        reqCode = "DLZSTZCX";
                        break;
                    case 14:
                        reqCode = "DLTYQCCX";
                        break;
                    default:
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                }
            }
            break;
            default:
                Resp.respCode = "-1";
                Resp.respInfo = "不支持该业务类型";
                break;
            //return Resp;
        }
        if ("-1".equals(Resp.respCode)) {
            Resp.writeBefore();
            Resp.writeEnd();
            return Resp;
        }
        Resp.writeBefore();
        try {
            //根据金额范围数循环查询
            int i = 1;
            while (StringHelper.hasAnyChar(getBankConfig().getMapValueByKey("amtRangeMapping", i + ""))) {
                String[] money = getBankConfig().getMapValueByKey("amtRangeMapping", i + "").split("-");
                if (money.length == 2) {
                    boolean flag = queryBillDetail(Double.parseDouble(money[0]), Double.parseDouble(money[1]), Resp, query, reqCode);
                    if (flag) {
                        WriteBankLogLn("查询金额范围：" + money[0] + "-" + money[1] + "成功");
                    } else {
                        WriteBankLogLn("查询金额范围：" + money[0] + "-" + money[1] + "失败");
                    }
                        if("DLTSFKQS".equals(reqCode)){
                            query.detail.overdueFlag ="2";
                            flag = queryBillDetail(Double.parseDouble(money[0]), Double.parseDouble(money[1]), Resp, query, reqCode);
                            if (flag) {
                                WriteBankLogLn("查询金额范围：" + money[0] + "-" + money[1] + "成功");
                            } else {
                                WriteBankLogLn("查询金额范围：" + money[0] + "-" + money[1] + "失败");
                            }
                            query.detail.overdueFlag ="1";
                        }
                }
                i++;
            }
            //double billAmtUp = getBankConfig().getValueAsFloat("BillAmtUP");
            //queryAllBill(0.00,billAmtUp,Resp,query,reqCode);
        } catch (Exception ex) {
            ex.printStackTrace();
            Resp = new RetAtsB001OperBillQry(query.reqHeader);
            Resp.respCode = "-1";
            Resp.respInfo = ex.getMessage();
            Resp.writeBefore();
        }
        Resp.writeEnd();
        return Resp;
//            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
//            XElement tmpElemnt = new XElement("stream", "");
//            tmpElemnt.addChild(new XElement("action", "DLBCMQJB"));
//            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
//            tmpElemnt.addChild(new XElement("reqCode", reqCode));
//            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
//            String dueDateDown = getBankConfig().getValueAsString("DueDateDown");
//            if(StringHelper.isNullOrEmpty(dueDateDown)){
//                Calendar calendar = Calendar.getInstance();
//                calendar.setTime(new Date());
//                calendar.add(Calendar.DAY_OF_MONTH,-5);
//                dueDateDown = Format.Date8Format.format(calendar.getTime());
//            }
//            tmpElemnt.addChild(new XElement("dueDateDown", dueDateDown));
//            String dueDateUp = getBankConfig().getValueAsString("DueDateUp");
//            if(StringHelper.isNullOrEmpty(dueDateUp)){
//                Calendar calendar = Calendar.getInstance();
//                calendar.setTime(new Date());
//                calendar.add(Calendar.YEAR,1);
//                dueDateUp = Format.Date8Format.format(calendar.getTime());
//            }
//            tmpElemnt.addChild(new XElement("dueDateUp", dueDateUp));
//            tmpElemnt.addChild(new XElement("dueDateDown", query.detail.dueDateDown));
//            tmpElemnt.addChild(new XElement("dueDateUp", query.detail.dueDateUp));
//            int billType = Integer.parseInt(query.detail.billType);
//            switch (billType) {
//                case 1:
//                    tmpElemnt.addChild(new XElement("billType", "AC01"));
//                    break;
//                case 2:
//                    tmpElemnt.addChild(new XElement("billType", "AC02"));
//                    break;
//            }
//            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
//            tmpElemnt.addChild(new XElement("orgName", ""));
//            tmpElemnt.addChild(new XElement("rcvName", ""));
//            if (!StringHelper.isNullOrEmpty(query.detail.billAmtDown)) {
//                double AmtDown = Double.valueOf(query.detail.billAmtDown);
//                tmpElemnt.addChild(new XElement("billAmtDown", String.format("%.2f", AmtDown)));
//            }
//            if (!StringHelper.isNullOrEmpty(query.detail.billAmtUp)) {
//                double AmtUp = Double.valueOf(query.detail.billAmtUp);
//                tmpElemnt.addChild(new XElement("billAmtUp", String.format("%.2f", AmtUp)));
//            }
//            tmpElemnt.addChild(new XElement("ecdsBatNo", ""));
//            if (reqCode.equals("DLTSFKSQ") || reqCode.equals("DLTSFKQS") || reqCode.equals("DLTSFKCX")) {
//                int overdueFlag = Integer.parseInt(query.detail.overdueFlag);
//                switch (overdueFlag) {
//                    case 1:
//                        tmpElemnt.addChild(new XElement("odueFlg", "01"));
//                        break;
//                    case 2:
//                        tmpElemnt.addChild(new XElement("odueFlg", "02"));
//                        break;
//                    default:
//                        Resp.respCode = "-1";
//                        Resp.respInfo = "逾期标志错误";
//                        Resp.writeBefore();
//                        Resp.writeEnd();
//                        return Resp;
//                }
//            }
//            if (reqCode.equals("DLZSTZSQ") || reqCode.equals("DLZSTZCX")) {
//                int recourseType = Integer.parseInt(query.detail.recourseType);
//                switch (recourseType) {
//                    case 1:
//                        tmpElemnt.addChild(new XElement("rcrsType", "RT00"));
//                        break;
//                    case 2:
//                        tmpElemnt.addChild(new XElement("rcrsType", "RT01"));
//                        break;
//                    default:
//                        Resp.respCode = "-1";
//                        Resp.respInfo = "追索类型错误";
//                        Resp.writeBefore();
//                        Resp.writeEnd();
//                        return Resp;
//                }
//
//            }
////        nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpXElement, getCharset());
//            xmlWriter.writeXElement(tmpElemnt);
//            xmlWriter.writeEndDocument();
//            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
//            if (tmpStrRet[0].length() == 0) {
//                StringBuilder tmpSbMsg = new StringBuilder();
//
//                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
//                if (tmpBkReader != null) {
//                    Resp.respInfo = tmpBkReader.getFirstText("/stream/statusText");
//                    if ("AAAAAAA".equals(tmpBkReader.getFirstText("/stream/status"))) {
//                        Resp.respCode = "0";
//                        //Resp.WriteBefore();
//                        int DetailCount = tmpBkReader.countElement("/stream/list/row");
//                        if (DetailCount > 0) {
//                            Resp.writeBefore();
//                            while (tmpBkReader.read("/stream/list/row")) {
//                                RetAtsB001OperBillQryDetail RespDetail = new RetAtsB001OperBillQryDetail();
//                                RespDetail.billNo = tmpBkReader.readedXElement.getSingleText("billNo");
//                                if (tmpBkReader.readedXElement.getSingleText("BILLTYP").equals("AC01")) {
//                                    RespDetail.billType = "1";
//                                } else {
//                                    RespDetail.billType = "2";
//                                }
//                                RespDetail.issDate = TransDate(tmpBkReader.readedXElement.getSingleText("ISSDATE"));
//                                RespDetail.dueDate = TransDate(tmpBkReader.readedXElement.getSingleText("DUEDATE"));
//                                RespDetail.billAmt = tmpBkReader.readedXElement.getSingleText("PAYAMT");
//                                if (tmpBkReader.readedXElement.getSingleText("ENDORMK").equals("EM00")) {
//                                    RespDetail.transFlag = "1";
//                                } else {
//                                    RespDetail.transFlag = "0";
//                                }
//                                if (tmpBkReader.readedXElement.getSingleText("ENDORMK").equals("CC00")) {
//                                    RespDetail.mustPay = "1";
//                                } else {
//                                    RespDetail.mustPay = "0";
//                                }
//                                RespDetail.drawName = tmpBkReader.readedXElement.getSingleText("DRWRNAM");
//                                RespDetail.drawCode = tmpBkReader.readedXElement.getSingleText("DRWRCOD");
//                                RespDetail.drawAct = tmpBkReader.readedXElement.getSingleText("DRWRACC");
//                                RespDetail.drawBnkCode = tmpBkReader.readedXElement.getSingleText("DRWRBNM");
//
//                                RespDetail.accpName = tmpBkReader.readedXElement.getSingleText("ACCPNAM");
//                                RespDetail.accpCode = tmpBkReader.readedXElement.getSingleText("ACCPCOD");
//                                RespDetail.accpAct = tmpBkReader.readedXElement.getSingleText("ACCPACC");
//                                RespDetail.accpBnkCode = tmpBkReader.readedXElement.getSingleText("ACCPBNM");
//
//                                RespDetail.payeeName = tmpBkReader.readedXElement.getSingleText("PYEENAM");
//                                RespDetail.payeeCode = tmpBkReader.readedXElement.getSingleText("PYEECOD");
//                                RespDetail.payeeAct = tmpBkReader.readedXElement.getSingleText("PYEEACC");
//                                RespDetail.payeeBnkCode = tmpBkReader.readedXElement.getSingleText("PYEEBNM");
//
//                                RespDetail.busiNo = tmpBkReader.readedXElement.getSingleText("BUSSQNO");
//                                RespDetail.busiType = query.detail.busiType;
//
//                                String tmpAPPDATE = tmpBkReader.readedXElement.getSingleText("APPDATE");
//                                if (!"".equals(tmpAPPDATE) && !"00000000".equals(tmpAPPDATE)) {
//                                    RespDetail.applyDate = TransDate(tmpAPPDATE);
//                                }
//                                RespDetail.applyName = tmpBkReader.readedXElement.getSingleText("APPNAME");
//                                RespDetail.applyCode = tmpBkReader.readedXElement.getSingleText("APPCODE");
//                                RespDetail.applyAct = tmpBkReader.readedXElement.getSingleText("APPACCT");
//                                RespDetail.applyBnkCode = tmpBkReader.readedXElement.getSingleText("APPBNM");
//
//                                RespDetail.receName = tmpBkReader.readedXElement.getSingleText("RCVNAME");
//                                RespDetail.receCode = tmpBkReader.readedXElement.getSingleText("RCVCODE");
//                                RespDetail.receAct = tmpBkReader.readedXElement.getSingleText("RCVACCT");
//                                RespDetail.receBnkCode = tmpBkReader.readedXElement.getSingleText("RCVBNM");
//
//                                RespDetail.memo = tmpBkReader.readedXElement.getSingleText("MEMO");
//                                RespDetail.contractNo = tmpBkReader.readedXElement.getSingleText("CONTRACTNO");
//                                RespDetail.invoiceNo = tmpBkReader.readedXElement.getSingleText("INVOICENO");
//
//                                if (tmpBkReader.readedXElement.getSingleText("RPDMARK").equals("RM00")) {
//                                    RespDetail.discType = "1";
//                                } else {
//                                    RespDetail.discType = "0";
//                                }
//                                if (tmpBkReader.readedXElement.getSingleText("STLMTHD").equals("SM00")) {
//                                    RespDetail.payType = "1";
//                                } else {
//                                    RespDetail.payType = "2";
//                                }
//
//                                String tmpRPDOPDT = tmpBkReader.readedXElement.getSingleText("RPDOPDT");
//                                if (!"".equals(tmpRPDOPDT) && !"00000000".equals(tmpRPDOPDT)) {
//                                    RespDetail.repOpenDate = TransDate(tmpRPDOPDT);
//                                }
//                                String tmpRPDDUDT = tmpBkReader.readedXElement.getSingleText("RPDDUDT");
//                                if (!"".equals(tmpRPDDUDT) && !"00000000".equals(tmpRPDDUDT)) {
//                                    RespDetail.repDueDate = TransDate(tmpRPDDUDT);
//                                }
//
//                                RespDetail.discRate = tmpBkReader.readedXElement.getSingleText("INTRRAT");
//                                RespDetail.repRate = tmpBkReader.readedXElement.getSingleText("RPDRATE");
//                                RespDetail.actedBnkCode = tmpBkReader.readedXElement.getSingleText("RECDBNM");
//                                RespDetail.overDueRea = tmpBkReader.readedXElement.getSingleText("ODUERSN");
//
//                                if (tmpBkReader.readedXElement.getSingleText("RCRSTYP").equals("RT00")) {
//                                    RespDetail.recourseType = "1";
//                                } else {
//                                    RespDetail.recourseType = "2";
//                                }
//
//                                RespDetail.recourseAmt = tmpBkReader.readedXElement.getSingleText("RCRSAMT");
//
//                                if (tmpBkReader.readedXElement.getSingleText("RCRSBCD").equals("RC00")) {
//                                    RespDetail.recourseCode = "1";
//                                } else {
//                                    RespDetail.recourseCode = "2";
//                                }
//
//                                String tmpBILSTAT = tmpBkReader.readedXElement.getSingleText("BILSTAT");
//                                if (!"".equals(tmpBILSTAT)) {
//                                    RespDetail.billStatus = tmpBILSTAT;
//                                }
//
//
//                                Resp.writeDetail(RespDetail);
//                            }
//
//                        } else if ("0".equals(Resp.respCode)) {
//                            Resp.respInfo = "记录为空";
//                            Resp.writeBefore();
//                        }
//                    } else {
//                        Resp.respCode = "-1";
//                        Resp.writeBefore();
//                    }
//                } else {
//                    Resp.respCode = "-1";
//                    Resp.respInfo = tmpSbMsg.toString();
//                    Resp.writeBefore();
//                    //Resp.Head();
//                }
//            } else {
//                Resp.respCode = "-1";
//                Resp.respInfo = tmpStrRet[1];
//                Resp.writeBefore();
//            }
//        }

    }


    public RetAtsB002BillTransQry D_B002_BillTrans(ReqB002BillTransQry query) throws Exception {
        RetAtsB002BillTransQry Resp = new RetAtsB002BillTransQry(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();

        String reqCode = "";
        int queryType = Integer.parseInt(query.queryType);
        int busiType = Integer.parseInt(query.busiType);
        switch (queryType) {
            case 1:
                switch (busiType) {
                    case 1:
                        reqCode = "DLBILREG";
                        break;
                    case 2:
                        reqCode = "DLTSCDSQ";
                        break;
                    case 3:
                        reqCode = "DLTSSPSQ";
                        break;
                    case 4:
                        reqCode = "DLBSZRSQ";
                        break;
                    case 5:
                        reqCode = "DLZHYASQ";
                        break;
                    case 6:
                        reqCode = "DLZYJCSQ";
                        break;
                    case 7:
                        reqCode = "DLBOZHSQ";
                        break;
                    case 8:
                        reqCode = "DLBOZHSQ";
                        break;
                    case 9:
                        reqCode = "DLBOZHSQ";
                        break;
                    case 10:
                        reqCode = "DLTIEXSQ";
                        break;
                    case 11:
                        reqCode = "DLTXSHSQ";
                        break;
                    case 12:
                        reqCode = "DLTSFKSQ";
                        break;
                    case 13:
                        reqCode = "DLZSTZSQ";
                        break;
                    case 14:
                        reqCode = "DLTYQCSQ";
                        break;
                    default:
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                }
                break;
            case 2:
                switch (busiType) {
                    case 1:
//                        reqCode = "";
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                    case 2:
                        reqCode = "DLTSCDQS";
                        break;
                    case 3:
                        reqCode = "DLTSSPQS";
                        break;
                    case 4:
                        reqCode = "DLBSZRQS";
                        break;
                    case 5:
                        reqCode = "DLZHYAQS";
                        break;
                    case 6:
                        reqCode = "DLZYJCQS";
                        break;
                    case 7:
                        reqCode = "DLBOZHQS";
                        break;
                    case 8:
                        reqCode = "DLBOZHQS";
                        break;
                    case 9:
                        reqCode = "DLBOZHQS";
                        break;
                    case 10:
                        reqCode = "DLTIEXQS";
                        break;
                    case 11:
                        reqCode = "DLTXSHQS";
                        break;
                    case 12:
                        reqCode = "DLTSFKQS";
                        break;
                    case 13:
//                        reqCode = "";
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                    case 14:
                        reqCode = "DLTYQCQS";
                        break;
                    default:
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                }
                break;
            case 3:
                switch (busiType) {
                    case 1:
                        reqCode = "DLWYTHSQ";
                        break;
                    case 2:
                        reqCode = "DLTSCDCX";
                        break;
                    case 3:
                        reqCode = "DLTSSPCX";
                        break;
                    case 4:
                        reqCode = "DLBSZRCX";
                        break;
                    case 5:
                        reqCode = "DLZHYACX";
                        break;
                    case 6:
                        reqCode = "DLZYJCCX";
                        break;
                    case 7:
                        reqCode = "DLBOZHCX";
                        break;
                    case 8:
                        reqCode = "DLBOZHCX";
                        break;
                    case 9:
                        reqCode = "DLBOZHCX";
                        break;
                    case 10:
                        reqCode = "DLTIEXCX";
                        break;
                    case 11:
                        reqCode = "DLTXSHCX";
                        break;
                    case 12:
                        reqCode = "DLTSFKCX";
                        break;
                    case 13:
                        reqCode = "DLZSTZCX";
                        break;
                    case 14:
                        reqCode = "DLTYQCCX";
                        break;
                    default:
                        Resp.respCode = "-1";
                        Resp.respInfo = "不支持该业务类型";
                        break;
                    //return Resp;
                }
                break;
            default:
                Resp.respCode = "-1";
                Resp.respInfo = "不支持该业务类型";
                break;
            //return Resp;
        }
        if ("-1".equals(Resp.respCode)) {
            Resp.writeBefore();
            return Resp;
        }
        xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
        XElement tmpElemnt = new XElement("stream", "");
        tmpElemnt.addChild(new XElement("action", "DLBCMQBH"));
        tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
        tmpElemnt.addChild(new XElement("accountNo", query.actNum));
        tmpElemnt.addChild(new XElement("reqCode", reqCode));
        tmpElemnt.addChild(new XElement("billNo", query.billNo));
        tmpElemnt.addChild(new XElement("bussqNo", query.busiNo));
//        nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpXElement, getCharset());
        xmlWriter.writeXElement(tmpElemnt);
        xmlWriter.writeEndDocument();
        String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
        //测试模拟报文

        //end

        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();

            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                Resp.respInfo = tmpBkReader.getFirstText("/stream/statusText");
                if ("AAAAAAA".equals(tmpBkReader.getFirstText("/stream/status"))) {
                    Resp.respCode = "0";
                    int DetailCount = tmpBkReader.countElement("/stream/list/row");
                    if (DetailCount > 0) {
                        Resp.writeBefore();
                        while (tmpBkReader.read("/stream/list/row")) {
                            RetAtsB002BillTransQryDetail RespDetail = new RetAtsB002BillTransQryDetail();

                            RespDetail.billNo = tmpBkReader.readedXElement.getSingleText("billNo");
                            RespDetail.busiType = tmpBkReader.readedXElement.getSingleText("BusiType");
                            if (tmpBkReader.readedXElement.getSingleText("ENDORMK").equals("EM00")) {
                                RespDetail.transFlag = "1";
                            } else {
                                RespDetail.transFlag = "0";
                            }
                            String tmpAPPDATE = tmpBkReader.readedXElement.getSingleText("APPDATE");
                            if (!"".equals(tmpAPPDATE) && !"00000000".equals(tmpAPPDATE)) {
                                RespDetail.applyDate = TransDate(tmpAPPDATE);
                            }
                            String tmpSGNRDAT = tmpBkReader.readedXElement.getSingleText("SGNRDAT");
                            if (!"".equals(tmpSGNRDAT) && !"00000000".equals(tmpSGNRDAT)) {
                                RespDetail.respDate = TransDate(tmpSGNRDAT);
                            }
                            RespDetail.applyName = tmpBkReader.readedXElement.getSingleText("APPNAME");
                            RespDetail.applyCode = tmpBkReader.readedXElement.getSingleText("APPCODE");
                            RespDetail.applyAct = tmpBkReader.readedXElement.getSingleText("APPACCT");

                            RespDetail.receName = tmpBkReader.readedXElement.getSingleText("RCVNAME");
                            RespDetail.receCode = tmpBkReader.readedXElement.getSingleText("RCVCODE");
                            RespDetail.receAct = tmpBkReader.readedXElement.getSingleText("RCVACCT");

                            RespDetail.memo = tmpBkReader.readedXElement.getSingleText("BACKMEM");
                            RespDetail.contractNo = tmpBkReader.readedXElement.getSingleText("CONTRACTNO");
                            RespDetail.invoiceNo = tmpBkReader.readedXElement.getSingleText("INVOICENO");
                            RespDetail.guarAddr = tmpBkReader.readedXElement.getSingleText("WAREADR");

                            if (tmpBkReader.readedXElement.getSingleText("DSNTTYP").equals("RM00")) {
                                RespDetail.discType = "1";
                            } else {
                                RespDetail.discType = "2";
                            }
                            if (tmpBkReader.readedXElement.getSingleText("STLMTHD").equals("SM00")) {
                                RespDetail.payType = "1";
                            } else {
                                RespDetail.payType = "2";
                            }
                            String tmpRPDOPDT = tmpBkReader.readedXElement.getSingleText("RPDOPDT");
                            if (!"".equals(tmpRPDOPDT) && !"00000000".equals(tmpRPDOPDT)) {
                                RespDetail.repOpenDate = TransDate(tmpRPDOPDT);
                            }
                            String tmpRPDDUDT = tmpBkReader.readedXElement.getSingleText("RPDDUDT");
                            if (!"".equals(tmpRPDDUDT) && !"00000000".equals(tmpRPDDUDT)) {
                                RespDetail.repDueDate = TransDate(tmpRPDDUDT);
                            }
                            RespDetail.discRate = tmpBkReader.readedXElement.getSingleText("INTRRAT");
                            RespDetail.discAmt = tmpBkReader.readedXElement.getSingleText("REALAMT");
                            RespDetail.repRate = tmpBkReader.readedXElement.getSingleText("RPDRATE");
                            RespDetail.repAmt = tmpBkReader.readedXElement.getSingleText("RPDAMNT");
                            RespDetail.proPayAmt = tmpBkReader.readedXElement.getSingleText("PPAYAMT");

                            RespDetail.overDueRea = tmpBkReader.readedXElement.getSingleText("ODUERSN");

                            if (tmpBkReader.readedXElement.getSingleText("RCRSTYP").equals("RT00")) {
                                RespDetail.recourseType = "1";
                            } else {
                                RespDetail.recourseType = "2";
                            }
                            Resp.writeDetail(RespDetail);
                        }
                    } else if ("0".equals(Resp.respCode)) {
                        Resp.respInfo = "记录为空";
                        Resp.writeBefore();
                    }
                } else {
                    Resp.respCode = "-1";
                    Resp.writeBefore();
                }
            } else {
                Resp.respCode = "-1";
                Resp.respInfo = tmpSbMsg.toString();
                Resp.writeBefore();
                //Resp.Head();
            }
        } else {
            Resp.respCode = "-1";
            Resp.respInfo = tmpStrRet[1];
            Resp.writeBefore();
        }
        Resp.writeEnd();
        return Resp;
    }

    RetAtsB004BillFrontQry D_B004_BillFront(ReqB004BillFrontQry query) throws Exception {
        RetAtsB004BillFrontQry Resp = new RetAtsB004BillFrontQry(query.reqHeader);
        Resp.writeStart();
        XmlTextWriter xmlWriter = new XmlTextWriter();
        String reqCode = "";
        //D_OperBill_Query_Resp Resp = new D_OperBill_Query_Resp();
        if (query.readRecord()) {
            int queryType = Integer.parseInt(query.detail.queryType);
            int busiType = Integer.parseInt(query.detail.busiType);
            switch (queryType) {
                case 1:
                    switch (busiType) {
                        case 1:
                            reqCode = "DLBILREG";
                            break;
//                            reqCode = "";
                        //Resp.respCode = "-1";
                        //Resp.respInfo = "不支持该业务类型";
                        //return Resp;
                        case 2:
                            reqCode = "DLTSCDSQ";
                            break;
                        case 3:
                            reqCode = "DLTSSPSQ";
                            break;
                        case 4:
                            reqCode = "DLBSZRSQ";
                            break;
                        case 5:
                            reqCode = "DLZHYASQ";
                            break;
                        case 6:
                            reqCode = "DLZYJCSQ";
                            break;
                        case 7:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 8:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 9:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 10:
                            reqCode = "DLTIEXSQ";
                            break;
                        case 11:
                            reqCode = "DLTXSHSQ";
                            break;
                        case 12:
                            reqCode = "DLTSFKSQ";
                            break;
                        case 13:
                            reqCode = "DLZSTZSQ";
                            break;
                        case 14:
                            reqCode = "DLTYQCSQ";
                            break;
                        default:
                            Resp.respCode = "-1";
                            Resp.respInfo = "不支持该业务类型";
                            break;//return Resp;
                    }
                    break;
                case 2: {
                    switch (busiType) {
                        case 1:
//                            reqCode = "";
                            Resp.respCode = "-1";
                            Resp.respInfo = "不支持该业务类型";
                            break;//return Resp;
                        case 2:
                            reqCode = "DLTSCDQS";
                            break;
                        case 3:
                            reqCode = "DLTSSPQS";
                            break;
                        case 4:
                            reqCode = "DLBSZRQS";
                            break;
                        case 5:
                            reqCode = "DLZHYAQS";
                            break;
                        case 6:
                            reqCode = "DLZYJCQS";
                            break;
                        case 7:
                            reqCode = "DLBOZHQS";
                            break;
                        case 8:
                            reqCode = "DLBOZHQS";
                            break;
                        case 9:
                            reqCode = "DLBOZHQS";
                            break;
                        case 10:
                            reqCode = "DLTIEXQS";
                            break;
                        case 11:
                            reqCode = "DLTXSHQS";
                            break;
                        case 12:
                            reqCode = "DLTSFKQS";
                            break;
                        case 13:
//                            reqCode = "";
                            Resp.respCode = "-1";
                            Resp.respInfo = "不支持该业务类型";
                            break;//return Resp;
                        case 14:
                            reqCode = "DLTYQCQS";
                            break;
                        default:
                            Resp.respCode = "-1";
                            Resp.respInfo = "不支持该业务类型";
                            break;//return Resp;
                    }
                }
                break;
                case 3: {
                    switch (busiType) {
                        case 1:
                            reqCode = "DLWYTHSQ";
                            break;
                        case 2:
                            reqCode = "DLTSCDCX";
                            break;
                        case 3:
                            reqCode = "DLTSSPCX";
                            break;
                        case 4:
                            reqCode = "DLBSZRCX";
                            break;
                        case 5:
                            reqCode = "DLZHYACX";
                            break;
                        case 6:
                            reqCode = "DLZYJCCX";
                            break;
                        case 7:
                            reqCode = "DLBOZHCX";
                            break;
                        case 8:
                            reqCode = "DLBOZHCX";
                            break;
                        case 9:
                            reqCode = "DLBOZHCX";
                            break;
                        case 10:
                            reqCode = "DLTIEXCX";
                            break;
                        case 11:
                            reqCode = "DLTXSHCX";
                            break;
                        case 12:
                            reqCode = "DLTSFKCX";
                            break;
                        case 13:
                            reqCode = "DLZSTZCX";
                            break;
                        case 14:
                            reqCode = "DLTYQCCX";
                            break;
                        default:
                            Resp.respCode = "-1";
                            Resp.respInfo = "不支持该业务类型";
                            break;//return Resp;
                    }
                }
                break;
                default:
                    Resp.respCode = "-1";
                    Resp.respInfo = "不支持该业务类型";
                    break;//return Resp;
            }
            if ("-1".equals(Resp.respCode)) {
                Resp.writeRetDetail();
                Resp.writeAfter();
                return Resp;
            }
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBCMBPQ"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("reqCode", reqCode));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("bussqNo", query.detail.busiNo));
            //        nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpXElement, getCharset());
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    Resp.respInfo = tmpBkReader.getFirstText("/stream/statusText");
                    if ("AAAAAAA".equals(tmpBkReader.getFirstText("/stream/status"))) {
                        Resp.respCode = "0";
                        //Resp.Head();
                        Resp.billNo = tmpBkReader.getFirstText("/stream/billNo");
                        if (tmpBkReader.getFirstText("/stream/BILLTYP").equals("AC01")) {
                            Resp.billType = "1";
                        } else {
                            Resp.billType = "2";
                        }
                        Resp.issDate = TransDate(tmpBkReader.getFirstText("/stream/ISSDATE"));
                        Resp.dueDate = TransDate(tmpBkReader.getFirstText("/stream/DUEDATE"));
                        Resp.billAmt = tmpBkReader.getFirstText("/stream/PAYAMT");
                        if (tmpBkReader.getFirstText("/stream/DFENDMK").equals("EM00")) {
                            Resp.transFlag = "1";
                        } else {
                            Resp.transFlag = "0";
                        }

                        Resp.drawName = tmpBkReader.getFirstText("/stream/DRWRNAM");
                        Resp.drawAct = tmpBkReader.getFirstText("/stream/DRWRACC");
                        Resp.drawBnkCode = tmpBkReader.getFirstText("/stream/DRWRBNM").trim();

                        Resp.creditLv = tmpBkReader.getFirstText("/stream/DRCDRAT");
                        Resp.gradeAgent = tmpBkReader.getFirstText("/stream/DRRAGCY");
                        String tmpRDUEDAT = tmpBkReader.getFirstText("/stream/RDUEDAT");
                        if (!StringHelper.isNullOrEmpty(tmpRDUEDAT)) {
                            Resp.gradeDueDate = TransDate(tmpRDUEDAT);
                        }
                        int drGuraDate = 0;
                        while (tmpBkReader.read("/stream/list[@name='drGrtList']/row")) {
                            int temp = Integer.parseInt(tmpBkReader.readedXElement.getSingleText("DRGRTDAT"));
                            if (temp > drGuraDate) {
                                drGuraDate = temp;
                                Resp.drGuarName = tmpBkReader.readedXElement.getSingleText("DRGRTNAM");
                                Resp.drGuarAddr = tmpBkReader.readedXElement.getSingleText("DRGRTADR");
                                Resp.drGuarDate = TransDate(tmpBkReader.readedXElement.getSingleText("DRGRTDAT"));
                            }
                        }
                        tmpBkReader.backToTop();
                        Resp.accpName = tmpBkReader.getFirstText("/stream/ACCPNAM");
                        Resp.accpAct = tmpBkReader.getFirstText("/stream/ACCPACC");
                        Resp.accpBnkCode = tmpBkReader.getFirstText("/stream/ACCPBNM").trim();
                        Resp.accpCredit = tmpBkReader.getFirstText("/stream/ACCDRAT");
                        Resp.accpGrade = tmpBkReader.getFirstText("/stream/ACRAGCY");

                        if (!StringHelper.isNullOrEmpty(tmpBkReader.getFirstText("/stream/ACRADAT"))) {
                            Resp.accpGradeDue = TransDate(tmpBkReader.getFirstText("/stream/ACRADAT"));
                        }
                        int apGuarDate = 0;
                        while (tmpBkReader.read("/stream/list[@name='acGrtList']/row")) {
                            int temp = Integer.parseInt(tmpBkReader.readedXElement.getSingleText("ACGRTDAT"));
                            if (temp > apGuarDate) {
                                apGuarDate = temp;
                                Resp.apGuarName = tmpBkReader.readedXElement.getSingleText("ACGRTNAM");
                                Resp.apGuarAddr = tmpBkReader.readedXElement.getSingleText("ACGRTADR");
                                Resp.apGuarDate = tmpBkReader.readedXElement.getSingleText("ACGRTDAT");
                            }
                        }
                        tmpBkReader.backToTop();
                        Resp.payeeName = tmpBkReader.getFirstText("/stream/PYEENAM");
                        Resp.payeeAct = tmpBkReader.getFirstText("/stream/PYEEACC");
                        Resp.payeeBnkCode = tmpBkReader.getFirstText("/stream/PYEEBNM").trim();
                        Resp.billState = tmpBkReader.getFirstText("/stream/BILSTAT");
                        String billState = getBillCurStatue(Resp.billNo,query.detail.actNum);
                        if(StringHelper.hasAnyChar(billState)){
                            Resp.billState = billState;
                        }
                    } else {
                        Resp.respCode = "-1";
                    }
                } else {
                    Resp.respCode = "-1";
                    Resp.respInfo = tmpSbMsg.toString();
                    //Resp.Head();
                }
            } else {
                Resp.respCode = "-1";
                Resp.respInfo = tmpStrRet[1];
            }
            Resp.writeRetDetail();
        }
        Resp.writeEnd();
        return Resp;
    }

    public RetAtsB005BillBackQry D_B005_BillBack(ReqB005BillBackQry query) throws Exception {
        RetAtsB005BillBackQry Resp = new RetAtsB005BillBackQry(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB005BillBackQryDetail detail = new RetAtsB005BillBackQryDetail();
            String reqCode = "";
            int queryType = Integer.parseInt(query.detail.queryType);
            int busiType = Integer.parseInt(query.detail.busiType);
            switch (queryType) {
                case 1:
                    switch (busiType) {
                        case 1:
                            reqCode = "DLBILREG";
                            break;
                        case 2:
                            reqCode = "DLTSCDSQ";
                            break;
                        case 3:
                            reqCode = "DLTSSPSQ";
                            break;
                        case 4:
                            reqCode = "DLBSZRSQ";
                            break;
                        case 5:
                            reqCode = "DLZHYASQ";
                            break;
                        case 6:
                            reqCode = "DLZYJCSQ";
                            break;
                        case 7:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 8:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 9:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 10:
                            reqCode = "DLTIEXSQ";
                            break;
                        case 11:
                            reqCode = "DLTXSHSQ";
                            break;
                        case 12:
                            reqCode = "DLTSFKSQ";
                            break;
                        case 13:
                            reqCode = "DLZSTZSQ";
                            break;
                        case 14:
                            reqCode = "DLTYQCSQ";
                            break;
                        default:
//                           Resp.respCode = "-1";
//                           Resp_Detail.respInfo = "";
//                           Resp.TransParam.DetailRecordList.Add(Resp_Detail);
                            detail.respCode = "-1";
                            detail.respInfo = "不支持该业务类型";
                            Resp.writeDetail(detail);
                            continue;
                            //return Resp;
                    }
                    break;
                case 2:
                    switch (busiType) {
                        case 1:
//                           reqCode = "";
//                           Resp_Detail.respCode = "-1";
//                           Resp_Detail.respInfo = "";
//                           Resp.TransParam.DetailRecordList.Add(Resp_Detail);
                            //return Resp;
                            detail.respCode = "-1";
                            detail.respInfo = "不支持该业务类型";
                            Resp.writeDetail(detail);
                            continue;
                        case 2:
                            reqCode = "DLTSCDQS";
                            break;
                        case 3:
                            reqCode = "DLTSSPQS";
                            break;
                        case 4:
                            reqCode = "DLBSZRQS";
                            break;
                        case 5:
                            reqCode = "DLZHYAQS";
                            break;
                        case 6:
                            reqCode = "DLZYJCQS";
                            break;
                        case 7:
                            reqCode = "DLBOZHQS";
                            break;
                        case 8:
                            reqCode = "DLBOZHQS";
                            break;
                        case 9:
                            reqCode = "DLBOZHQS";
                            break;
                        case 10:
                            reqCode = "DLTIEXQS";
                            break;
                        case 11:
                            reqCode = "DLTXSHQS";
                            break;
                        case 12:
                            reqCode = "DLTSFKQS";
                            break;
                        case 13:
//                           reqCode = "";
//                           Resp_Detail.respCode = "-1";
//                           Resp_Detail.respInfo = "";
//                           Resp.TransParam.DetailRecordList.Add(Resp_Detail);
                            //return Resp;
                            detail.respCode = "-1";
                            detail.respInfo = "不支持该业务类型";
                            Resp.writeDetail(detail);
                            continue;
                        case 14:
                            reqCode = "DLTYQCQS";
                            break;
                        default:
//                           Resp_Detail.respCode = "-1";
//                           Resp_Detail.respInfo = "";
//                           Resp.TransParam.DetailRecordList.Add(Resp_Detail);
                            //return Resp;
                            detail.respCode = "-1";
                            detail.respInfo = "不支持该业务类型";
                            Resp.writeDetail(detail);
                            continue;
                    }
                    break;
                case 3:
                    switch (busiType) {
                        case 1:
                            reqCode = "DLWYTHSQ";
                            break;
                        case 2:
                            reqCode = "DLTSCDCX";
                            break;
                        case 3:
                            reqCode = "DLTSSPCX";
                            break;
                        case 4:
                            reqCode = "DLBSZRCX";
                            break;
                        case 5:
                            reqCode = "DLZHYACX";
                            break;
                        case 6:
                            reqCode = "DLZYJCCX";
                            break;
                        case 7:
                            reqCode = "DLBOZHCX";
                            break;
                        case 8:
                            reqCode = "DLBOZHCX";
                            break;
                        case 9:
                            reqCode = "DLBOZHCX";
                            break;
                        case 10:
                            reqCode = "DLTIEXCX";
                            break;
                        case 11:
                            reqCode = "DLTXSHCX";
                            break;
                        case 12:
                            reqCode = "DLTSFKCX";
                            break;
                        case 13:
                            reqCode = "DLZSTZCX";
                            break;
                        case 14:
                            reqCode = "DLTYQCCX";
                            break;
                        default:
//                           Resp_Detail.respCode = "-1";
//                           Resp_Detail.respInfo = "";
//                           Resp.TransParam.DetailRecordList.Add(Resp_Detail);
                            //return Resp;
                            detail.respCode = "-1";
                            detail.respInfo = "不支持该业务类型";
                            Resp.writeDetail(detail);
                            continue;
                    }
                    break;
                default:
//                   Resp_Detail.respCode = "-1";
//                   Resp_Detail.respInfo = "";
//                   Resp.TransParam.DetailRecordList.Add(Resp_Detail);
                    detail.respCode = "-1";
                    detail.respInfo = "不支持该业务类型";
                    Resp.writeDetail(detail);
                    continue;

            }
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBCMQBH"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            tmpElemnt.addChild(new XElement("reqCode", reqCode));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("bussqNo", query.detail.busiNo));
            //        nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpXElement, getCharset());
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetMsg = tmpBkReader.getFirstText("/stream/statusText");
                    if ("AAAAAAA".equals(tmpBkReader.getFirstText("/stream/status"))) {
                        detail.respCode = "0";
                        if ("0".equals(tmpBkReader.getFirstText("/stream/totalNum"))) {
                            detail.respCode = "-1";
                            detail.respInfo = "记录为空";
                            Resp.writeDetail(detail);
                        } else {
                            while (tmpBkReader.read("/stream/list/row")) {
                                detail = new RetAtsB005BillBackQryDetail();
                                detail.respInfo = tmpRetMsg;//tmpBkReader.getFirstText("/stream/statusText");
                                detail.respCode = "0";
                                //RetAtsB005BillBackQryDetail RespDetail = new RetAtsB005BillBackQryDetail();
                                detail.billNo = tmpBkReader.readedXElement.getSingleText("billNo");
                                String infoType = tmpBkReader.readedXElement.getSingleText("INFOTYP");
                                if (infoType.equals("01"))
                                    detail.transCode = "2";
                                else if (infoType.equals("02"))
                                    detail.transCode = "3";
                                else if (infoType.equals("03"))
                                    detail.transCode = "10";
                                else if (infoType.equals("04"))
                                    detail.transCode = "11";
                                else if (infoType.equals("05"))
                                    detail.transCode = "12";
                                else if (infoType.equals("06"))
                                    detail.transCode = "13";
                                else if (infoType.equals("07"))
                                    detail.transCode = "14";
                                else if (infoType.equals("08"))
                                    detail.transCode = "15";
                                else if (infoType.equals("09"))
                                    detail.transCode = "16";
                                else if (infoType.equals("10"))
                                    detail.transCode = "25";
                                else if (infoType.equals("11") || infoType.equals("110") || infoType.equals("111") || infoType.equals("112"))
                                    detail.transCode = "17";
                                else if (infoType.equals("12"))
                                    detail.transCode = "18";
                                else if (infoType.equals("13"))
                                    detail.transCode = "19";
                                else if (infoType.equals("14"))
                                    detail.transCode = "20";
                                else if (infoType.equals("15"))
                                    detail.transCode = "21";
                                else if (infoType.equals("16"))
                                    detail.transCode = "22";
                                if (tmpBkReader.readedXElement.getSingleText("ENDORMK").equals("EM00")) {
                                    detail.transFlag = "1";
                                } else {
                                    detail.transFlag = "0";
                                }
                                String tmpAPPDATE = tmpBkReader.readedXElement.getSingleText("APPDATE");
                                if (!StringHelper.isNullOrEmpty(tmpAPPDATE) && !"00000000".equals(tmpAPPDATE)) {
                                    detail.applyDate = TransDate(tmpAPPDATE);
                                }
                                String tmpSGNRDAT = tmpBkReader.readedXElement.getSingleText("SGNRDAT");
                                if (!StringHelper.isNullOrEmpty(tmpSGNRDAT) && !"00000000".equals(tmpSGNRDAT)) {
                                    detail.respDate = TransDate(tmpSGNRDAT);
                                }
                                detail.applyName = tmpBkReader.readedXElement.getSingleText("APPNAME");
                                detail.receName = tmpBkReader.readedXElement.getSingleText("RCVNAME");
                                detail.guarAddr = tmpBkReader.readedXElement.getSingleText("WAREADR");
                                String tmpRPDOPDT = tmpBkReader.readedXElement.getSingleText("RPDOPDT");
                                if (!StringHelper.isNullOrEmpty(tmpRPDOPDT) && !"".equals(tmpRPDOPDT)) {
                                    detail.repOpenDate = TransDate(tmpRPDOPDT);
                                }
                                String tmpRPDDUDT = tmpBkReader.readedXElement.getSingleText("RPDDUDT");
                                if (!StringHelper.isNullOrEmpty(tmpRPDDUDT) && !"".equals(tmpRPDDUDT)) {
                                    detail.repDueDate = TransDate(tmpRPDDUDT);
                                }
                                if (tmpBkReader.readedXElement.getSingleText("RCRSTYP").equals("RT00")) {
                                    detail.recourseType = "1";
                                } else {
                                    detail.recourseType = "2";
                                }
                                Resp.writeDetail(detail);
                            }
                        }
                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = tmpRetMsg;
                        Resp.writeDetail(detail);
                    }
                } else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpSbMsg.toString();
                    Resp.writeDetail(detail);
                    //Resp.Head();
                }
            } else {
                detail.respCode = "-1";
                detail.respInfo = tmpStrRet[1];
                Resp.writeDetail(detail);
            }
        }
        Resp.writeEnd();
        return Resp;
    }

    public RetAtsB006BillStateQry D_B006_BillState(ReqB006BillStateQry query) throws Exception {
        RetAtsB006BillStateQry Resp = new RetAtsB006BillStateQry(query.reqHeader);
        XmlTextWriter xmlWriter = new XmlTextWriter();
        Resp.writeBeforeDetail();
        while (query.readRecord()) {
            RetAtsB006BillStateQryDetail detail = new RetAtsB006BillStateQryDetail();
            String reqCode;
            int OperType = Integer.parseInt(query.detail.operType);
            int BusiType = Integer.parseInt(query.detail.busiType);
            switch (OperType) {
                case 1:
                    switch (BusiType) {
                        case 1:
                            if ((!StringHelper.isNullOrEmpty(query.detail.autoPromptAccept) &&
                                    !StringHelper.isNullOrEmpty(query.detail.autoPromptReceipt) &&
                                    query.detail.autoPromptAccept.equals("0") &&
                                    query.detail.autoPromptReceipt.equals("0") ||
                                    StringHelper.isNullOrEmpty(query.detail.autoPromptAccept) ||
                                    StringHelper.isNullOrEmpty(query.detail.autoPromptReceipt))) {
                                reqCode = "DLBILREG";
                            } else if (query.detail.autoPromptAccept != null &&
                                    query.detail.autoPromptReceipt != null &&
                                    query.detail.autoPromptAccept.equals("1") &&
                                    query.detail.autoPromptReceipt.equals("0")) {
                                reqCode = "DLBLREG2";
                            } else if (query.detail.autoPromptAccept != null &&
                                    query.detail.autoPromptReceipt != null &&
                                    query.detail.autoPromptReceipt.equals("1")) {
                                reqCode = "DLBLREG3";
                            } else {
//                            detail.respCode = "-1";
//                            detail.respInfo = "";
//                            Resp.TransParam.DetailRecordList.Add(detail);
                                detail.respCode = "-1";
                                detail.respInfo = "不支持的业务类型";
                                Resp.writeDetail(detail);
                                continue;
                            }
                            break;
                        case 2:
                            reqCode = "DLTSCDSQ";
                            break;
                        case 3:
                            reqCode = "DLTSSPSQ";
                            break;
                        case 4:
                            reqCode = "DLBSZRSQ";
                            break;
                        case 5:
                            reqCode = "DLZHYASQ";
                            break;
                        case 6:
                            reqCode = "DLZYJCSQ";
                            break;
                        case 7:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 8:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 9:
                            reqCode = "DLBOZHSQ";
                            break;
                        case 10:
                            reqCode = "DLTIEXSQ";
                            break;
                        case 11:
                            reqCode = "DLTXSHSQ";
                            break;
                        case 12:
                            reqCode = "DLTSFKSQ";
                            break;
                        case 13:
                            reqCode = "DLZSTZSQ";
                            break;
                        case 14:
                            reqCode = "DLTYQCSQ";
                            break;
                        default:
//                        detail.respCode = "-1";
//                        detail.respInfo = "";
//                        Resp.TransParam.DetailRecordList.Add(detail);
                            detail.respCode = "-1";
                            detail.respInfo = "不支持的业务类型";
                            Resp.writeDetail(detail);
                            continue;

                    }
                    break;
                case 2:
                case 3:
                    switch (BusiType) {
                        case 1:
//                            detail.respCode = "-1";
//                            detail.respInfo = "";
//                            Resp.TransParam.DetailRecordList.Add(detail);
                            detail.respCode = "-1";
                            detail.respInfo = "不支持的业务类型";
                            Resp.writeDetail(detail);
                            continue;
                        case 2:
                            reqCode = "DLTSCDQS";
                            break;
                        case 3:
                            reqCode = "DLTSSPQS";
                            break;
                        case 4:
                            reqCode = "DLBSZRQS";
                            break;
                        case 5:
                            reqCode = "DLZHYAQS";
                            break;
                        case 6:
                            reqCode = "DLZYJCQS";
                            break;
                        case 7:
                            reqCode = "DLBOZHQS";
                            break;
                        case 8:
                            reqCode = "DLBOZHQS";
                            break;
                        case 9:
                            reqCode = "DLBOZHQS";
                            break;
                        case 10:
                            reqCode = "DLTIEXQS";
                            break;
                        case 11:
                            reqCode = "DLTXSHQS";
                            break;
                        case 12:
                            reqCode = "DLTSFKQS";
                            break;
                        case 13:
//                            detail.respCode = "-1";
//                            detail.respInfo = "";
//                            Resp.TransParam.DetailRecordList.Add(detail);
                            detail.respCode = "-1";
                            detail.respInfo = "不支持的业务类型";
                            Resp.writeDetail(detail);
                            continue;
                        case 14:
                            reqCode = "DLTYQCQS";
                            break;
                        default:
//                            detail.respCode = "-1";
//                            detail.respInfo = "";
//                            Resp.TransParam.DetailRecordList.Add(detail);
                            detail.respCode = "-1";
                            detail.respInfo = "不支持的业务类型";
                            Resp.writeDetail(detail);
                            continue;
                    }
                    break;
                case 4:
                    switch (BusiType) {
                        case 1:
                            reqCode = "DLWYTHSQ";
                            break;
                        case 2:
                            reqCode = "DLTSCDCX";
                            break;
                        case 3:
                            reqCode = "DLTSSPCX";
                            break;
                        case 4:
                            reqCode = "DLBSZRCX";
                            break;
                        case 5:
                            reqCode = "DLZHYACX";
                            break;
                        case 6:
                            reqCode = "DLZYJCCX";
                            break;
                        case 7:
                            reqCode = "DLBOZHCX";
                            break;
                        case 8:
                            reqCode = "DLBOZHCX";
                            break;
                        case 9:
                            reqCode = "DLBOZHCX";
                            break;
                        case 10:
                            reqCode = "DLTIEXCX";
                            break;
                        case 11:
                            reqCode = "DLTXSHCX";
                            break;
                        case 12:
                            reqCode = "DLTSFKCX";
                            break;
                        case 13:
                            reqCode = "DLZSTZCX";
                            break;
                        case 14:
                            reqCode = "DLTYQCCX";
                            break;
                        default:
//                            detail.respCode = "-1";
//                            detail.respInfo = "";
//                            Resp.TransParam.DetailRecordList.Add(detail);
                            detail.respCode = "-1";
                            detail.respInfo = "不支持的业务类型";
                            Resp.writeDetail(detail);
                            continue;
                    }
                    break;
                default:
//                    detail.respCode = "-1";
//                    detail.respInfo = "";
//                    Resp.TransParam.DetailRecordList.Add(detail);
                    detail.respCode = "-1";
                    detail.respInfo = "不支持的业务类型";
                    Resp.writeDetail(detail);
                    continue;
            }
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBCMSTK"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("reqCode", reqCode));
            tmpElemnt.addChild(new XElement("clientID", query.detail.reqSeqID));
            //        nodeAnalysis(p_req1908.singleDetail.srcXElement, tmpXElement, getCharset());
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String retMsg = tmpBkReader.getFirstText("/stream/statusText");
                    String retCode = tmpBkReader.getFirstText("/stream/status");
                    if ("AAAAAAA".equals(retCode)) {
                        if (tmpBkReader.read("/stream/list/row")) {
                            detail.respCode = "0";
                            detail.respInfo = tmpBkReader.readedXElement.getSingleText("statusText");
                            detail.billNo = tmpBkReader.readedXElement.getSingleText("BILLNO");
                            String TRASTAT = tmpBkReader.readedXElement.getSingleText("TRASTAT");
                            if("1".equals(query.detail.operType)){
                                if("1".equals(query.detail.busiType)
                                        &&"A03".equals(TRASTAT)) {
                                    TRASTAT = "DLBILREG+" + TRASTAT;
                                }
                            }else if("4".equals(query.detail.operType)){
                                if("1".equals(query.detail.busiType)
                                        &&"A03".equals(TRASTAT)) {
                                    TRASTAT = "DLWYTHSQ+" + TRASTAT;
                                }else{
                                    TRASTAT = "3+" + TRASTAT;
                                }
                            }
                            detail.transState = TRASTAT;
                            detail.payInfoCode = detail.transState;
                            detail.billState = tmpBkReader.readedXElement.getSingleText("BILSTAT");
                            //Resp.writeDetail(detail);
                        }
                    } else if ("ED08091".equals(retCode)) {
                        detail.respCode = "0";
                        detail.respInfo = retMsg;
                        //detail.BillNo = tmpBkReader.readedXElement.getSingleText("BILLNO");
                        detail.transState = retCode;
                        detail.payInfoCode = retCode;
                        //detail.BillState = tmpBkReader.readedXElement.getSingleText("BILSTAT");

                    } else {
                        detail.respCode = "-1";
                        detail.respInfo = retMsg;
                    }

                } else {
                    detail.respCode = "-1";
                    detail.respInfo = tmpSbMsg.toString();
                }
            } else {
                detail.respCode = "-1";
                detail.respInfo = tmpStrRet[1];
            }
            Resp.writeDetail(detail);
        }
        Resp.writeEnd();
        return Resp;
    }

    public RetAtsB007BillKzsrQry D_B007_BillKzsr(ReqB007BillKzsrQry query) throws Exception {
        RetAtsB007BillKzsrQry Resp = new RetAtsB007BillKzsrQry(query.reqHeader);
        if (query.readRecord()) {
            RetAtsB007BillKzsrQryDetail detail = new RetAtsB007BillKzsrQryDetail();
            XmlTextWriter xmlWriter = new XmlTextWriter();
            Resp.writeBeforeDetail();
            xmlWriter.writeStartDocByDeclaration("<?xml version=\"1.0\" encoding=\"GBK\"?>");
            XElement tmpElemnt = new XElement("stream", "");
            tmpElemnt.addChild(new XElement("action", "DLBRCQZS"));
            tmpElemnt.addChild(new XElement("userName", bankFront.loginName));
            tmpElemnt.addChild(new XElement("billNo", query.detail.billNo));
            tmpElemnt.addChild(new XElement("accountNo", query.detail.actNum));
            xmlWriter.writeXElement(tmpElemnt);
            xmlWriter.writeEndDocument();
            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String retMsg = tmpBkReader.getFirstText("/stream/statusText");
                    String retCode = tmpBkReader.getFirstText("/stream/status");
                    if ("AAAAAAA".equals(retCode)) {
                        Resp.respCode = "0";
                        Resp.respInfo = retMsg;//tmpBkReader.readedXElement.getSingleText("statusText");
                        Resp.billNo = query.detail.billNo;//tmpBkReader.readedXElement.getSingleText("BillNo");
                        Resp.writeRespInfos();
                        while (tmpBkReader.read("/stream/list/row")) {
                            detail.receName = tmpBkReader.readedXElement.getSingleText("RCVGNME");
                            detail.receCode = tmpBkReader.readedXElement.getSingleText("RECRCOD");
                            detail.receAct = tmpBkReader.readedXElement.getSingleText("RCVGACC");
                            detail.receBnkCode = tmpBkReader.readedXElement.getSingleText("RCVGBNM");
                            Resp.writeDetail(detail);
                        }
                    } else {
                        Resp.respCode = "-1";
                        Resp.respInfo = retMsg;
                        Resp.writeRespInfos();
                    }
                } else {
                    Resp.respCode = "-1";
                    Resp.respInfo = tmpSbMsg.toString();
                    Resp.writeRespInfos();
                }
            } else {
                Resp.respCode = "-1";
                Resp.respInfo = tmpStrRet[1];
                Resp.writeRespInfos();
            }
        }
        Resp.writeEnd();
        return Resp;
    }

}
